﻿
using System;
using System.Configuration;
using CRM.SQLiteHelper;
using System.Data.SQLite;
using CRM.SqlHelper;

namespace CRM.SQLiteHelper
{
    public class PubConstant
    {
        /// <summary>
        /// 获取连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                //数据库连接字符串
                SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();

                sb.DataSource = string.Format("{0}bin\\data\\{1}", System.Web.HttpContext.Current.Request.PhysicalApplicationPath, "CRM.db");


                //sb.Password = "tonGDp0498db0mcd";


                string _connectionString = sb.ToString();

                string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
                if (ConStringEncrypt == "true")
                {
                    _connectionString = DESEncrypt.Decrypt(_connectionString);
                }
                return _connectionString;
            }
        }

        /// <summary>
        /// 得到web.config里配置项的数据库连接字符串。
        /// </summary>
        /// <param name="configName"></param>
        /// <returns></returns>
        public static string GetConnectionString(string configName)
        {
            string connectionString = ConfigurationManager.AppSettings[configName];
            string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
            if (ConStringEncrypt == "true")
            {
                connectionString = DESEncrypt.Decrypt(connectionString);
            }
            return connectionString;
        }


    }
}
